package com.lczyfz.campusinfo.modules.campusinfopay.service;

import com.lczyfz.campusinfo.common.enums.CampusinfoOrderStat;
import com.lczyfz.campusinfo.common.service.CrudService;
import com.lczyfz.campusinfo.modules.campusinfoorder.dao.CampusinfoOrderDao;
import com.lczyfz.campusinfo.modules.campusinfoorder.entity.CampusinfoOrder;
import com.lczyfz.campusinfo.modules.campusinfoorder.service.CampusinfoOrderService;
import com.lczyfz.campusinfo.modules.campusinfopay.entity.CampusinfoPay;
import com.lczyfz.campusinfo.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
@Service
@Transactional(readOnly = false)
public class PayOrderUitl {
    @Autowired
    private CampusinfoOrderService campusinfoOrderService;
    @Autowired
    private CampusinfoPayService campusinfoPayService;
    public String Orderpay(String orderType){
        CampusinfoOrder campusinfoOrder = new CampusinfoOrder();
        campusinfoOrder.setSeqTag(orderType);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
        campusinfoOrderService.save(campusinfoOrder);
        String getmax = campusinfoOrderService.getmax();
        String Stringdata = sdf.format(new Date());
        return orderType+Stringdata+getmax;
    }
    public void SaveOrder(String orderCode,String payMethod,String goodName,String payMent){
        CampusinfoPay campusinfoPay = new CampusinfoPay();
        campusinfoPay.setId(orderCode);//订单号
        campusinfoPay.setPaytype(payMethod); //支付方法
        campusinfoPay.setStat(CampusinfoOrderStat.UNDONE.getValue()); //支付状态 //默认状态为未完成
        campusinfoPay.setUser(UserUtils.getUser()); //用户名称
        campusinfoPay.setGoodsName(goodName); //订单名称
        campusinfoPay.setAmount(payMent);//费用
        campusinfoPayService.ordersave(campusinfoPay); //保存订单号
    }
}
